
const express = require('express');
const fs = require('fs');

const serverBundle = require('./data.json');
const clientManifest = require('./data.json');
const template = fs.readFileSync('./index.html', 'utf-8');
const renderer = require('vue-server-renderer').createBundleRenderer(serverBundle, {
	template,
	clientManifest
});

const server = express();

server.get('/', (req, res) => {
	renderer.renderToString({
		title: 'ice-cream',
		meta: `<meta name="viewport" content="width=decive-width, initial-scale=1.0">`
	}, (err, html) => {
		console.log(err);
		if(err) return res.status(500).end('Internal Server Error.');

		res.setHeader('Content-Type', 'text/html; charset=utf8');
		res.end(html);
	})
})

server.listen(3000, () => {
	console.log('server running at port 3000.');
})

